const LoginToken = 'token'
const setUserInfoToken=(token)=>{
    // localStorage.setItem(LoginToken,token);
    // setCookie(LoginToken,token)
    // setCookie(LoginToken,token,100)
}
const getToken=()=>{
    const token = getCookie(LoginToken);
    return token;
}
// 沒有token時不携带token字段
const getSelfHeader=()=>{
    const cookie = getToken();
    if(cookie!==null){
        return {
            "token" : cookie
        }
    }else{
        return {}
    }
}
export const removeToken=()=>{
    // localStorage.removeItem(LoginToken);
    setCookie(LoginToken,'',-1)
}



// 函数中的参数分别为 cookie 的名称、值以及过期天数
function setCookie(c_name,value,expiredays){
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
        ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

/*
// 设置过期时间以秒为单位
function setCookie(c_name,value,expireseconds){
    var exdate=new Date();
    exdate.setTime(exdate.getTime()+expireseconds * 1000);
    document.cookie=c_name+ "=" +escape(value)+
        ((expireseconds==null) ? "" : ";expires="+exdate.toGMTString())
}
*/


function getCookie(name){
    return localStorage.getItem(LoginToken)
/*    const reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"),
        arr = document.cookie.match(reg);
    if (arr !== null) {
        return arr[2];
    } else {
        return null;
    }*/
}
